#include <iostream>
using namespace std;
int n, m, k;

struct disk
{
    int id;
    int num;
    int preid;
    disk()
    {
        id = num = preid = 0;
    }
};
disk *dk;

int write(int id, int l, int r, int num)
{
    int i = l;
    for (i; i <= r; i++)
    {
        //表示现在正占用或者没有占用
        if (dk[i].id == id || dk[i].id == 0)
        {
            dk[i].num = num;
            dk[i].id = id;
        }
        else
        {
            break;
        }
    }
    //完全被占用
    if (i == l)
    {
        return -1;
    }
    //部分占用
    else
    {
        return i - 1;
    }
}

int del(int id, int l, int r)
{
    int i = l;
    bool flag = true;
    for (i; i <= r; i++)
    {
        if (dk[i].id != id)
        {
            flag = false;
            break;
        }
        else
        {
            continue;
        }
    }
    if (flag)
    {
        for (i = l; i <= r; i++)
        {
            dk[i].id = 0;
            dk[i].preid = id;
        }
        return 1;
    }
    else
    {
        return 0;
    }
}

int recover(int id, int l, int r)
{
    int i = l;
    bool flag = true;
    for (i; i <= r; i++)
    {
        if (dk[i].preid != id || dk[i].id != 0)
        {
            flag = false;
            break;
        }
        else
        {
            continue;
        }
    }
    if (flag)
    {
        for (i = l; i <= r; i++)
        {
            dk[i].id = id;
        }
        return 1;
    }
    else
    {
        return 0;
    }
}

int read(int p)
{
    if (dk[p].id == p)
        return 1;
    else
        return 0;
}

int main()
{
    cin >> n >> m >> k;
    dk = new disk[m + 10];
    for (int i = 0; i < k; i++)
    {
        int op;
        cin >> op;
        if (op == 0)
        {
            int id, l, r, x;
            cin >> id >> l >> r >> x;
            cout << write(id, l, r, x) << endl;
        }

        if (op == 1)
        {
            int id, l, r;
            cin >> id >> l >> r;
            if (del(id, l, r))
            {
                cout << "OK" << endl;
            }
            else
            {
                cout << "FAIL" << endl;
            }
        }

        if (op == 2)
        {
            int id, l, r;
            cin >> id >> l >> r;
            if (recover(id, l, r))
            {
                cout << "OK" << endl;
            }
            else
            {
                cout << "FAIL" << endl;
            }
        }

        if (op == 3)
        {
            int p;
            cin >> p;
            if (read(p))
            {
                cout << dk[p].id << " " << dk[p].num << endl;
            }
            else
            {
                cout << 0 << " " << 0 << endl;
            }
        }
    }
    delete[] dk;
    dk = NULL;
    // system("pause");
    return 0;
}